﻿using HCService.Client;
using Net.Entity;
using System;
using System.Collections.Generic;
using System.Text;

namespace HCService.MsgHandler.SubHandler
{
	public class ClientRequestUser : HandlerBase
	{
		public new string HandleTag = "req.entity.user";
		public ClientRequestUser(PackHandlerCenter center) {
			center.RegisterPackHandle(HandleTag, Handle);
		}

		public override void Handle(IClient client, Pack pack)
		{
			if (pack.HandleTag == this.HandleTag) {
				Net.Entity.User user = Net.Entity.User.Parser.ParseFrom(pack.PackBuffer);

				user.Nickname = "测试用户";
				user.Createtime = @"2020/8/12";

				user.Ip = client.GetClientIp();
				user.Platform = "Faker Platform";
				user.Attr = new Net.Entity.Attr()
				{
					Exp = 20,
					Level = 10,
				};

				var lstItem = new List<Net.Entity.Item>()
				{
					new Net.Entity.Item(){  Id = 101 , Attr = new Net.Entity.Attr() { Param1 = 10 } },
					new Net.Entity.Item(){  Id = 102 , Attr = new Net.Entity.Attr() { Param1 = 10 } },
					new Net.Entity.Item(){  Id = 103 , Attr = new Net.Entity.Attr() { Param1 = 10 } },
				};
				user.Item.AddRange(lstItem);

				var lstRole = new List<Net.Entity.Role>()
				{
					new Net.Entity.Role(){ Id = 101, Attr = new Net.Entity.Attr(){ Level = 2, Exp = 20 } },
					new Net.Entity.Role(){ Id = 102, Attr = new Net.Entity.Attr(){ Level = 2, Exp = 20 } },
				};
				user.Role.AddRange(lstRole);

				user.Userinfo = new Achieve();

				client.Send("req.entity.user", user);
			}
			
		}
	}
}
